package com.gqr.threadsafe;

import java.util.HashMap;
import java.util.Map;

/**
 * Copyright (C), 2020-2024,gqr
 * FileName:MultiThreadError3
 * author:guqingrong
 * Date:2024-04-27 10:31
 * Description:发布逸出
 * History:
 * <author>    <time>    <version>    <desc>
 * 作者姓名     修改时间     版本号        描述
 */
public class MultiThreadError3 {
    private Map<String, String> states;

    public MultiThreadError3() {
        states = new HashMap<>();
        states.put("1", "周一");
        states.put("2", "周二");
        states.put("3", "周三");
        states.put("4", "周四");
    }

    public Map<String, String> getStates() {

        return states;
    }

    /**
     * 返回states的副本 不返回states原始对象
     * 这样对副本的修改不会影响原始对象
     * @return
     */
    public Map<String, String> getStatesCopy() {
        return new HashMap<>(states);
    }

    public static void main(String[] args) {
        MultiThreadError3 error3 = new MultiThreadError3();
        Map<String, String> states = error3.getStates();
//        System.out.println(states.get("1"));
//        states.remove("1");
//        System.out.println(states.get("1"));
        System.out.println(error3.getStatesCopy().get("1"));
        error3.getStatesCopy().remove("1");
        System.out.println(error3.getStatesCopy().get("1"));
    }

}
